<?php

class Setting extends Model
{
    public function tableName()
    {
        return 'setting';
    }

    public function rules()
    {
        return array(
            array('name, value', 'required'),
            array('name, value', 'length', 'max' => 255),
            array('name, value', 'safe', 'on' => 'search'),
        );
    }

    public function relations()
    {
        return array();
    }

    public function attributeLabels()
    {
        return array(
            'name' => 'Name',
            'value' => 'Value',
        );
    }

    public function search()
    {
        $criteria = new CDbCriteria;

        $criteria->compare('name', $this->name, true);
        $criteria->compare('value', $this->value, true);

        return new CActiveDataProvider($this, array(
            'criteria' => $criteria,
        ));
    }

    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public static function value($name){
        $model = $this->findByAttributes(array('name'=>$name));
        return $model->value;
    }
}
